
import React from "react";
import createYGCPage from '../../components/CreateYGCPage/index.jsx'

import "./index.less";

import Table from "bee-table";
import 'bee-table/build/Table.css';

import { searchTpl } from './tpl/searchTpl.js'
import { setTableTpl } from './tpl/tableTpl.js'
import { queryProject } from './orgIndicators.config.js'

import { vendorsSetUrl, vendorsTrimStr, vendorsDanger, vendorsFmtDate, vendorsSuccess, vendorsGetUrlParam } from 'utils/config.js';


class OrgIndicators extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            data: []
        };
        this.srcHeight = 60;
        this.columns = setTableTpl(this);
        this.searchTpl = searchTpl;
    }
    componentDidMount() {

    }

    componentWillUnmount() {


    }

    searchAfterEvent = (refPk) => {

        if (refPk === 'pkSrc') {
            let org = this.props.search.getSearchValue({ refPk: 'pkSrc', requireKey: 'pkSrc' });
            if (org && org.length && org[0] == null) {
                this.props.search.setSearchItemDisabled('pkProjectType', true)
                this.props.search.emptySearchItemValue('pkProjectType')
            } else {
                this.props.search.setSearchItemDisabled('pkProjectType', false)
            }
        }
    }

    render() {
        let { searchTpl } = this.state;
        console.log(this.props.search)
        return (

            <div className="ygc-list">
                <div className='ygc-list-header-area'>
                    <div className='ygc-list-header-title'>组织指标统计表</div>
                </div>
                <div className="ygc-search-Area">
                    {this.props.YGCCreateSearch(this.searchTpl, {
                        searchBtnClick: this.searchBtnClick,
                        searchAfterEvent: this.searchAfterEvent
                    })}
                </div>
                <div className="ygc-table-Area">
                    <div className="ygc-projectIndicators-table">
                        <Table
                            className='project_table'
                            columns={this.columns}
                            data={this.state.data}
                            emptyText={() => '暂无数据'}
                            rowKey={this.setRowKey}
                            // scroll={{ y: 460 }}
                            bordered
                        />
                    </div>
                </div>
            </div>

        )
    }


    searchBtnClick = (searchInfo) => {
        let params = {
            pkOrg: searchInfo['pkSrc'].length ? searchInfo['pkSrc'][0] : null,
            pkProject: searchInfo['pkProject'].length ? searchInfo['pkProject'] : null,
            pkMeasureindex: searchInfo['pkMeasureindex'].length ? searchInfo['pkMeasureindex'] : null,
            pkProjectType: searchInfo['pkProjectType'].length ? searchInfo['pkProjectType'] : null,
            startDate: searchInfo['sectionDate'].startTime ? Date.parse(searchInfo['sectionDate'].startTime) : null,
            endDate: searchInfo['sectionDate'].endTime ? Date.parse(searchInfo['sectionDate'].endTime) : null
        }

        console.log(params)
        queryProject(params).then((res) => {
            let data = res.data;
            console.log('yan', data)
            if (data.resultCode === 'ok') {
                if (data.result) {
                    vendorsSuccess({ 'text': `查询成功,共${data.result.length}条` })
                } else {
                    vendorsSuccess({ 'text': `查询成功` })
                }
                this.setState({
                    data: data.result == null ? [] : data.result
                })
            } else {
                vendorsDanger({ 'text': data.exMsg })
            }
        })
    }

    setProjectTypeShowCol = (key, record) => {
        return record.projectTypeShowVOS && record.projectTypeShowVOS.map((item) => {
            let sumNumHeight = 0;
            item.indexExcelShowVOS && item.indexExcelShowVOS.map(indexExceitem => {
                if (indexExceitem.projectShowVOS) {
                    sumNumHeight += indexExceitem.projectShowVOS.length
                }
            })
            return (
                <div
                    style={{ height: `${this.srcHeight * sumNumHeight}px` }}
                    className={'scheduleVosItem itemP'}
                >
                    {item[key]}
                </div>
            )
        })

    }

    setIndexExcelShowCol = (key, record) => {
        return record.projectTypeShowVOS && record.projectTypeShowVOS.map((item) => {
            return item.indexExcelShowVOS && item.indexExcelShowVOS.map(indexExceitem => {
                let sumNumHeight = indexExceitem.projectShowVOS.length;
                return (
                    <div
                        style={{ height: `${this.srcHeight * sumNumHeight}px` }}
                        className={'scheduleVosItem itemP'}
                    >
                        {indexExceitem[key]}
                    </div>
                )
            })
        })

    }

    setProjectItemCol = (key, record) => {
        return record.projectTypeShowVOS && record.projectTypeShowVOS.map((item) => {
            return item.indexExcelShowVOS && item.indexExcelShowVOS.map(indexExceitem => {
                return indexExceitem.projectShowVOS && indexExceitem.projectShowVOS.map(projectItem => {
                    return (
                        <div
                            style={{ height: `${this.srcHeight}px` }}
                            className={'scheduleVosItem itemP'}
                        >
                            {projectItem[key]}
                        </div>
                    )
                })
            })
        })
    }

    setRowKey = (record, index) => {
        return index
    };
}

export default createYGCPage({})(OrgIndicators);
